<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <input type='text' placeholder="请输入城市名称" value="郑州" id="city">
        <br>
        <button id="btn">查询</button>
        <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"></script>
        <script>
            $(function(){
                $('#btn').click(function(){
                    $.ajax({
                        url:'http://apis.baidu.com/apistore/weatherservice/citylist',
                        type:'get',
                        dataType:'json',
                        data:{cityname:$("#city").val()},
                        headers:{apikey:"764bea985cfd0e960fdca55c95d26f27"},
                        success:function(data){
                           if(data.errMsg=='success'){
                               var retData = data.retData;
                               for(var i=0;i<retData.length;i++){
                                  var city_obj = retData[i] ;
                                  console.log(city_obj.area_id);
                                  console.log(city_obj.name_cn);
                           }
                        }
                        }
                    })
                }) 
            })
        </script>
    </body>
</html>
